package bearworker.zxl.config;

import bearworker.zxl.server.ServerStart;
import bearworker.zxl.utils.PriviUtil;
import bearworker.zxl.utils.UrlUtil;
import org.apache.log4j.Logger;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.*;
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
import org.springframework.core.env.Environment;

import javax.annotation.Resource;

/**
 * Created by 逍遥的熊 on 2017/11/20.
 */

@Configuration
@PropertySource(value = "classpath:base.properties")
@EnableAspectJAutoProxy
@Import({DatabaseConfig.class,RedisConfig.class,StaticDataConfig.class})
@ComponentScan(basePackages = {"bearworker.zxl.service","bearworker.zxl.dao","bearworker.zxl.utils"})
@MapperScan(basePackages={"bearworker.zxl.dao.mapper"})
public class AppConfig {

    private Logger logger = Logger.getLogger(AppConfig.class);

    @Resource
    private Environment environment;

    @Bean(name = "initPrivi",initMethod = "updUserPriv")
    @DependsOn("redisTemplate")
    public PriviUtil initPrivi(){
        return new PriviUtil();
    }

    @Bean
    public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() {
        return new PropertySourcesPlaceholderConfigurer();
    }

    @Bean(name = "serverStart",initMethod = "start",destroyMethod = "destory")
    public ServerStart serverStart(){
        return new ServerStart(environment.getRequiredProperty("netty.port",Integer.class));
    }

}
